package level4Assessment;

import java.sql.Time;
import java.util.Date;

public class PrePaidParkingTransaction extends ParkingTransaction{
	
	DriveUpParkingTransaction driveUp;

	private String registrationNumber;
	private int arrivalHour;
	private int arrivalMinute;
	protected static double hoursStaying;
	private int expiryHour;
	private int expiryMin;
	private int lengthHour;
	private int lengthMin;
	Date date = new Date();
	double totalCost = 0;
	
	public PrePaidParkingTransaction(String registrationNumber, int arrivalHour, int arrivalMinute, int expiryHour, int expiryMinute, int hoursStaying) 
	{
		this.registrationNumber = registrationNumber;
		this.arrivalHour = arrivalHour;
		this.arrivalMinute = arrivalMinute;
		this.hoursStaying = ((expiryHour*1000) + expiryMinute) - ((arrivalHour*1000) + arrivalMinute);
		this.expiryHour = expiryHour;
		this.expiryMin = expiryMinute;
		lengthHour = expiryHour - arrivalHour;
		lengthMin  = expiryMin - arrivalMinute;
	}

	@Override
	public double calculateTotalCost() {
		CreditCardValidation newCardValidation = new CreditCardValidation();
		if(date.getHours() >= expiryHour)
		{
			OverstayedParkingTransaction overstayedParkingTransaction = new OverstayedParkingTransaction(registrationNumber, arrivalHour, arrivalMinute, expiryHour, expiryMin,(int)hoursStaying);
			overstayedParkingTransaction.calculateTotalCost();
			TransactionWriter newTransactionWriter = new TransactionWriter(arrivalHour, registrationNumber, arrivalHour, arrivalMinute, expiryHour, expiryMin, lengthHour, lengthMin, overstayedParkingTransaction.calculateTotalCost());
			super.displayToTerminal(registrationNumber, Math.round(hoursStaying/1000), overstayedParkingTransaction.calculateTotalCost());
			AuthorisationWriter authorisationWriter = new AuthorisationWriter(transactionNum, 'o', newCardValidation.getCcCardNum(), newCardValidation.getCcExpiryDate(), newCardValidation.isCCValid(), newCardValidation.ccValidation());
		}else
		{
			super.displayToTerminal(registrationNumber, Math.round(hoursStaying/1000), totalCost);
			TransactionWriter newTransactionWriter = new TransactionWriter(arrivalHour, registrationNumber, arrivalHour, arrivalMinute, expiryHour, expiryMin, lengthHour, lengthMin, totalCost);
			AuthorisationWriter authorisationWriter = new AuthorisationWriter(transactionNum, 'p', newCardValidation.getCcCardNum(), newCardValidation.getCcExpiryDate(), newCardValidation.isCCValid(), newCardValidation.ccValidation());
		}
		return totalCost;
	}
}
